#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMouseEvent>
#include <QListWidget>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include "photoshow.h"
#include <vector>

typedef struct
{
    uint16_t x;
    uint16_t y;
}Point;

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT
    #define PHOTO_WIDTH 800
    #define PHOTO_HEIGTH 480
public:
    MainWindow(QWidget *parent = nullptr);
    void Widget_Init(void);

    ~MainWindow();



protected:
    void mousePressEvent(QMouseEvent *e);
    void mouseMoveEvent(QMouseEvent *e);
    void mouseReleaseEvent(QMouseEvent *e);

private:
    QPoint last;

    Ui::MainWindow *ui;
    QSerialPort *serial;
    PhotoShow* photo;
    std::vector<Point> valid_points;
    uint8_t img_data[PHOTO_WIDTH][PHOTO_HEIGTH];
    QVector<QRgb> vcolorTable; //生成灰度颜色表

    void Clean_Notes(void);
    void Update_Notes(int color);
    QImage Pk8bitGrayToQIm(const unsigned char *pBuffer, const int &bufWidth, const int &bufHight);

private slots:
    void ImgClicked(QListWidgetItem*);
};
#endif // MAINWINDOW_H
